package com.sky.controller.admin;

import com.sky.Result.PageResult;
import com.sky.Result.Result;
import com.sky.model.dto.UserDTO;
import com.sky.model.dto.UserPageQueryDTO;
import com.sky.model.entity.User;
import com.sky.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminUserController")
@Slf4j
@RequestMapping("/admin/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户分页查询
     * @param userPageQueryDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(@RequestBody UserPageQueryDTO userPageQueryDTO) {
        log.info("分页查询：{}", userPageQueryDTO);
        PageResult pageResult = userService.pageQuery(userPageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 新增用户
     * @param userDTO
     * * @return
     * */
    @PostMapping("/save")
    @ApiOperation("新增用户")
    public Result save(@RequestBody UserDTO userDTO){
        log.info("新增用户：{}", userDTO);
        userService.save(userDTO);
        return Result.success();
    }

    /**
     * 批量启用禁用用户
     * @param ids
     * @return
     */
    @PostMapping("/status")
    @ApiOperation("批量启用禁用用户")
    public  Result startOrstops (@RequestBody List<Long> ids){
        log.info("用户批量启用禁用，ids:{}",ids);
        userService.startOrstops(ids);
        return Result.success();
    }

    /**
     * 批量删除用户
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("删除用户")
/*    public Result delete(@RequestBody List<Long> ids) {
        log.info("用户批量删除操作，ids:{}", ids);
        userService.delete(ids);
        return Result.success();
    }*/
    public  Result delete (@RequestBody List<Long> ids){
        log.info("用户批量删除操作，ids:{}", ids);
        userService.delete(ids);
        return Result.success();
    }
    /**修改用户信息
     * @param userDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody User userDTO) {
        log.info("修改用户信息：userDTO{}", userDTO);
        userService.update(userDTO);
        return Result.success();
    }
}
